<?php
/**
 * Pagination 
 * 
 * @author Mitchelle Pascual <mitch.pascual@gmail.com>
 * $date 04/01/2010
 *
 */
class Owg_List_PageInfo
{
	protected $m_aData = array();
	protected $m_iCurrentPage;
	protected $m_iPageOffset; // start
	protected $m_iNbItems; // limit
	protected $m_iTotalItems;
	protected $m_iTotalPages;
	protected $m_iPageRange;
	
	public function __construct()
	{
	}
	
	public function setCurrentPage($p_iCurrentPage)
	{
		$this->m_iCurrentPage = $p_iCurrentPage;
		return $this;
	}
	
	public function getCurrentPage()
	{
		return $this->m_iCurrentPage;
	}	
	
	
	public function setPageOffset($p_iPageOffset)
	{
		$this->m_iPageOffset = $p_iPageOffset;
		return $this;
	}
	
	public function getPageOffset()
	{
		return (self::getCurrentPage() - 1) * self::getNbItems();
	}
	
	
	public function setNbItems($p_iNbItems)
	{
		$this->m_iNbItems = $p_iNbItems;
		return $this;
	}
	
	public function getNbItems()
	{
		return $this->m_iNbItems;
	}	
	
	public function getTotalItems()
	{
		return $this->m_iTotalItems;
	}
	
	public function setTotalItems($p_iTotalItems)
	{
		$this->m_iTotalItems = $p_iTotalItems;
		return $this;
	}

	public function getTotalPages()
	{
		$this->m_iTotalPages = self::getTotalItems() / self::getNbItems();
		return $this->m_iTotalPages;
	}
	
	public function setPageRange($p_iPageRange)
	{
		$this->m_iPageRange = $p_iPageRange;
		return $this;
	}

	
	public function getPageRange()
	{
		return $this->m_iPageRange;
	}
	
	public function setData(array $p_aData)
	{
		$this->m_aData = $p_aData;
	}
	
	public function getData()
	{
		return $this->m_aData;
	}

	
	public function pagination() 
	{
		$paginator = Zend_Paginator::factory(self::getData());
		$paginator->setCurrentPageNumber(self::getCurrentPage());
		$paginator->setItemCountPerPage(self::getNbItems());
		$paginator->setPageRange(self::getPageRange());
		$pageInfo = $paginator->getPages();

		return array('paginationInfo' => $pageInfo, 'url' => self::_url());
	}		
	
	private function _url()
	{
		$url = Owg_Utility_Url::url('page');
		return $url;
	}
	
	
}